package day_2022_9_to_12.Day;

/**
 * @author haomin
 * @date 2022/09/24 17:30
 **/
public class Day23_1_Num1652_Decrypt {
    class Solution {
        public int[] decrypt(int[] code, int k) {
            int n = code.length;
            int[] res = new int[n];
            if(k != 0){
                for(int i = 0; i < n; ++i){
                    int count = Math.abs(k);
                    int sum = 0;
                    int index = k > 0 ? i + 1 : i - 1;
                    while(count-- > 0){
                        if(index == n) index = 0;
                        if(index == -1) index = n-1;
                        sum += code[index];
                        if(k > 0) index++;
                        else index--;
                    }
                    res[i] = sum;
                }
            }
            return res;
        }
    }
}